<?php

/**
 * EmailLogFilter class
 *
 * @author Julot
 * @since Wednesday, June 6, 2012. 02:05 PM
 */
class LogFilter extends CLogFilter {

	public $ignoreCategories;

	public function filter(&$logs) {
		// unset categories marked as "ignored"
		if ($logs)
			foreach ($logs as $logKey=>$log) {
				$logCategory = $log[2]; //log category
				foreach ($this->ignoreCategories as $nocat) {
					if ($logCategory === $nocat) {
						// Exact match
						unset($logs[$logKey]);
						continue;
					} else if (strpos($nocat, '.*') !== false) {
						// Wildcard match
						// remove asterix item from array and add dot at the end
						$nocat = str_replace('.*', '', $nocat) . '.';
						if (strpos($logCategory . '.', $nocat) !== false) {
							unset($logs[$logKey]);
						}
					}
				}
			}

		$this->format($logs);
		return $logs;
	}

}
